package com.tanhua.dubbo.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @Description: test
 * @Create by: JJ菜菜
 * @Date: 2021/11/28 0:12
 */

// 自动填充类

@Component
public class MyMetaObjectHandler implements MetaObjectHandler {


    @Override
    public void insertFill(MetaObject metaObject) {

        Object created = getFieldValByName("created", metaObject);
        if(null == created){
            setFieldValByName("created", new Date(), metaObject);
        }

        Object updated = getFieldValByName("updated", metaObject);
        if (null == updated){
            setFieldValByName("updated", new Date(), metaObject);
        }

    }

    @Override
    public void updateFill(MetaObject metaObject) {

        // 更新时候就直接更新
        setFieldValByName("updated",  new Date(), metaObject);

    }
}
